package com.kele.demo;

import com.kele.demo.config.EnvironmentModule;
import com.kele.demo.utils.BeanUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import java.util.Arrays;

/**
 * @author chunhui.li
 * @date 2022/2/11 15:08
 * @Description
 * @ClassName ConsumerDemoApplication
 */
@SpringBootApplication
@EnableFeignClients
public class ConsumerDemoApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(ConsumerDemoApplication.class, args);
        Environment environment = context.getBean(Environment.class);
        getEnv(environment);
        BeanUtil.applicationContext = context;
//        System.out.println(environment.getProperty("server.port") + " ==>名字 " + environment.getProperty("spring.application.name"));
    }

    @Bean(name = "serviceEnv")
    public static EnvironmentModule getEnv(Environment environment) {
        EnvironmentModule environmentModule = new EnvironmentModule();
        environmentModule.setPort(environment.getProperty("server.port"));
        environmentModule.setServiceId(environment.getProperty("spring.application.name"));
        return environmentModule;
    }
}
